package com.liangwj.springbootweb.services.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.liangwj.springbootweb.mapper.UserMapper;
import com.liangwj.springbootweb.model.User;
import com.liangwj.springbootweb.services.IMybatisUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <b>Description:</b> mybatis user Service impl <br/>
 * @author Lingwenjun
 * @date 2019/1/3-13:54
 * @version 1.0
 */
@Service
public class MybatisUserServiceImpl implements IMybatisUserService {

    @Autowired
    private UserMapper userMapper;

    @Override
    public void createUser(User user) {
        userMapper.insert(user);
    }

    /**
     * /*
     *     * 这个方法中用到了我们开头配置依赖的分页插件pagehelper
     *     * 很简单，只需要在service层传入参数，然后将参数传递给一个插件的一个静态方法即可；
     *     * pageNum 开始页数
     *     * pageSize 每页显示的数据条数
     *     * */
    @Override
    public PageInfo<User> finaAllUserByPage(int num, int size) {
        PageHelper.startPage(num, size);
        List<User> userList = userMapper.selectAllUsers();
        return new PageInfo<>(userList);
    }
}
